package com.sgb.kjwl.view.ui.adapter.packers;

import android.graphics.Color;
import android.util.TypedValue;

import androidx.annotation.Nullable;
import androidx.databinding.DataBindingUtil;
import androidx.recyclerview.widget.GridLayoutManager;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.fondesa.recyclerviewdivider.DividerDecoration;
import com.sgb.kjwl.BR;
import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.ItemTeamAlbumBinding;
import com.sgb.kjwl.model.entity.packers.TeamAlbumEntity;


import java.util.List;
import java.util.Map;

/**
 * @author: 王彬臣
 * @date: 2021/9/9
 * @Description: 工队相册Adapter
 */
public class TeamAlbumAdapter extends BaseQuickAdapter<TeamAlbumEntity, BaseViewHolder> {
    /**
     * 是否显示复选框
     */
    boolean isShowEdit;

    public onItemClickListener onItemClickListener;


    public void setOnItemClickListener(TeamAlbumAdapter.onItemClickListener onItemClickListener) {
        this.onItemClickListener = onItemClickListener;
    }

    public void setShowEdit(boolean showEdit) {
        isShowEdit = showEdit;
    }

    public TeamAlbumAdapter(@Nullable @org.jetbrains.annotations.Nullable List<TeamAlbumEntity> data) {
        super(R.layout.item_team_album,data);
    }

    @Override
    protected void convert(BaseViewHolder helper, TeamAlbumEntity item) {
        ItemTeamAlbumBinding mBinding = DataBindingUtil.bind(helper.itemView);
        mBinding.setVariable(BR.viewModel, item);
        mBinding.ryUrls.setLayoutManager(new GridLayoutManager(mContext,4));
        if( mBinding.ryUrls.getItemDecorationCount() == 0) {
            DividerDecoration.builder(mContext)
                    .color(Color.TRANSPARENT)
                    .size(7, TypedValue.COMPLEX_UNIT_DIP)
                    .build()
                    .addTo(mBinding.ryUrls);
        }
        AlbumImageAdapter imageAdapter=new AlbumImageAdapter(mContext,null,null,10,helper.getLayoutPosition());
        mBinding.ryUrls.setAdapter(imageAdapter);
        imageAdapter.setNetImgList(item.getTeamUrlList());
        imageAdapter.setOnMainItemClickListener(new AlbumImageAdapter.onMainItemClickListener() {//点击子Item获取主Item位置
            @Override
            public void onItemClick(int position) {
                if(onItemClickListener!=null){
                    onItemClickListener.onItemClick(position);
                }
            }

            @Override
            public void getDelMap(int mainPosition, Map<Integer, String> delMap) {

                if(onItemClickListener!=null){
                    onItemClickListener.getDel(mainPosition,delMap);
                }
            }
        });


        if(isShowEdit){
            imageAdapter.setShowEdit(true);
        }else{
            imageAdapter.setShowEdit(false);
        }
    }
   public interface onItemClickListener{
         void onItemClick(int position);

         void getDel(int mainPosition,Map<Integer,String> delMap);
    }
}
